Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable service account token auth for public API #5254

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

matiasb
Copy link
Contributor

@matiasb matiasb commented Nov 13, 2024

Related to https://github.com/grafana/oncall-private/issues/2826

Continuing work started in #5211, this adds support for Grafana service accounts tokens for API authentication (except alert group actions which will still require a user behind). Next steps would be updating the go client and the terraform provider to allow service account token auth for OnCall resources.

Following proposal 1.1 from doc.

@matiasb matiasb added pr:no public docs Added to a PR that does not require public documentation updates release:patch PR will be added to "Other Changes" section of release notes labels Nov 13, 2024
@matiasb matiasb force-pushed the matiasb/public-api-service-account-auth branch from 1e382db to 29c3858 Compare November 13, 2024 17:58
@matiasb matiasb marked this pull request as ready for review November 13, 2024 19:45
@matiasb matiasb requested a review from a team as a code owner November 13, 2024 19:45
related_name="alert_receive_channels",
blank=True,
null=True,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to keep track of integrations created via a service account token.

organization = Organization.objects.filter(grafana_url=grafana_url).first()
if organization:
return organization

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to identify the Grafana URL to hit its API when validating a service account token (note Grafana URL is already a param in Terraform)

permissions = get_service_account_token_permissions(organization, token)
if not permissions:
try:
user, auth_token = ServiceAccountToken.validate_token(organization, token)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation is moved to the ServiceAccountToken model.

return super().get_queryset().select_related("service_account__organization")


class ServiceAccountToken(BaseAuthToken):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most relevant bits of this PR are here.

@matiasb matiasb force-pushed the matiasb/public-api-service-account-auth branch from 5f6712b to 1bb8e0d Compare November 18, 2024 19:09
@matiasb matiasb added this pull request to the merge queue Nov 19, 2024
Merged via the queue into dev with commit 2bcbac8 Nov 19, 2024
25 checks passed
@matiasb matiasb deleted the matiasb/public-api-service-account-auth branch November 19, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates release:patch PR will be added to "Other Changes" section of release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants